﻿using System.Linq;
using YiCheap.Core.Data;
using YiCheap.Core.Domain.Localization;

namespace YiCheap.Service.Installation
{
    public class InstallationService:IInstallationService
    {
        private IRepository<Language> _languageRepository;

        public void InstallData()
        {
            InstallLanguage();
            InstallLocaleResources();
        }

        private void InstallLanguage()
        {
            var language = new Language
                               {
                                   Name = "English",
                                   LanguageCulture = "en-US",
                                   UniqueSeoCode = "en",
                                   FlagImageFileName = "us.png",
                                   Published = true,
                                   DisplayOrder = 1
                               };
            _languageRepository.Insert(language);
        }

        protected virtual void InstallLocaleResources()
        {
            //'English' language
            var language = _languageRepository.Table.Where(l => l.Name == "English").Single();


            language.LocaleStringResources.Add(
                            new LocaleStringResource()
                            {
                                ResourceName = "Post.Product.Name",
                                ResourceValue = "Product Name" 
                            });


            language.LocaleStringResources.Add(
                            new LocaleStringResource()
                            {
                                ResourceName = "Post.Product.ShortDescription",
                                ResourceValue = "Short Description"
                            }); 
            
            language.LocaleStringResources.Add(
                          new LocaleStringResource()
                          {
                              ResourceName = "Post.Product.FullDescription",
                              ResourceValue = "Full Description"
                          });

            language.LocaleStringResources.Add(
                         new LocaleStringResource()
                         {
                             ResourceName = "Post.Product.Picture",
                             ResourceValue = "Picture"
                         });

            language.LocaleStringResources.Add(
                         new LocaleStringResource()
                         {
                             ResourceName = "Post.Product.Price",
                             ResourceValue = "Price"
                         });


            _languageRepository.Update(language);
        }
    }
}